package com.happyfamily.springboot.crowdsourcingplatform.controller.weng;

import com.happyfamily.springboot.crowdsourcingplatform.base.result.PageTableRequest;
import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.dto.IndustryDto;
import com.happyfamily.springboot.crowdsourcingplatform.dto.LatestInfoDto;
import com.happyfamily.springboot.crowdsourcingplatform.model.IndustryDynamics;
import com.happyfamily.springboot.crowdsourcingplatform.model.LastestInfomation;
import com.happyfamily.springboot.crowdsourcingplatform.service.weng.IndustryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Slf4j
public class IndustryDynamicsController
{
	@Autowired
	IndustryService industryService;

	@GetMapping("/api-back/industryDynamics/list")
	@ResponseBody
	@ApiOperation(value = "分页获取行业动态", notes = "分页获取行业动态")
	public Results<IndustryDynamics> getAllIndustryByPage(PageTableRequest request)
	{
		request.countOffset();
		return industryService.getAllIndustryByPage(request.getOffset(), request.getLimit());
	}


	@GetMapping("/api-back/industryDynamics/delete")
	@ResponseBody
	@PreAuthorize("hasAuthority('back:industry:delete')")
	@ApiOperation(value = "通过ID删除行业动态", notes = "通过ID删除行业动态")
	public Results<IndustryDynamics> delete(IndustryDto industryDto)
	{
		industryService.deleteIndustry(industryDto.getNid());
		return Results.success();
	}

	@GetMapping("/api-back/industryDynamics/open")
	@ResponseBody
	@PreAuthorize("hasAuthority('back:industry:update')")
	@ApiOperation(value = "通过ID发布动态", notes = "通过ID发布动态")
	public Results<IndustryDynamics> open(IndustryDto industryDto)
	{
		industryService.openIndustry(industryDto.getNid());
		return Results.success();
	}

	@GetMapping("/api-back/industryDynamics/close")
	@ResponseBody
	@PreAuthorize("hasAuthority('back:industry:update')")
	@ApiOperation(value = "通过ID下架动态", notes = "通过ID下架动态")
	public Results<IndustryDynamics> close(IndustryDto industryDto)
	{
		industryService.closeIndustry(industryDto.getNid());
		return Results.success();
	}

	@GetMapping("/api-back/industryDynamics/findIndustryByFuzzy")
	@ResponseBody
	@PreAuthorize("hasAuthority('back:industry:query')")
	@ApiOperation(value = "模糊查询动态", notes = "模糊查询动态")
	public Results<IndustryDynamics> getIndustryByFuzzy(PageTableRequest requests, String ntitle, String getDate, String ncontent)
	{
		requests.countOffset();
		return industryService.getIndustryByFuzzy(ntitle, getDate, ncontent, requests.getOffset(), requests.getLimit());
	}

	@GetMapping("/api-back/industryDynamics/edit")
	@ResponseBody
	@PreAuthorize("hasAuthority('back:industry:update')")
	@ApiOperation(value = "通过ID修改动态标题", notes = "通过ID修改动态标题")
	public Results<IndustryDynamics> industryEdit(IndustryDto industryDto)
	{
		industryService.industryEdit(industryDto.getNid(), industryDto.getNtitle());
		return Results.success();
	}

	@GetMapping("/industryDynamics/frontGetIndustryByShu")
	@ResponseBody
	@ApiOperation(value = "前端获取数码通讯行业动态", notes = "前端获取数码通讯行业动态")
	public List<IndustryDynamics> frontGetIndustryByShu()
	{
		return industryService.frontGetIndustryByShu();
	}

	@GetMapping("/industryDynamics/frontGetIndustryBySheng")
	@ResponseBody
	@ApiOperation(value = "前端获取生活服务行业动态", notes = "前端获取生活服务行业动态")
	public List<IndustryDynamics> frontGetIndustryBySheng()
	{
		return industryService.frontGetIndustryBySheng();
	}

	@GetMapping("/industryDynamics/frontGetIndustryByZhi")
	@ResponseBody
	@ApiOperation(value = "前端获取智能硬件行业动态", notes = "前端获取智能硬件行业动态")
	public List<IndustryDynamics> frontGetIndustryByZhi()
	{
		return industryService.frontGetIndustryByZhi();
	}

	@GetMapping("/industryDynamics/frontGetIndustryByRu")
	@ResponseBody
	@ApiOperation(value = "前端获取软件科学行业动态", notes = "前端获取软件科学行业动态")
	public List<IndustryDynamics> frontGetIndustryByRu()
	{
		return industryService.frontGetIndustryByRu();
	}

}
